﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Profile;

namespace demo1.sysadmin
{
    public partial class userRoles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //添加角色
        public void addUsersToRoles(string user, string role)
        {
            ////using System.Web.Security;
            ////using System.Web.Profile;
            //System.Web.Security.MembershipCreateStatus staus;
            ////删除用户
            //bool isDeleted = System.Web.Security.Membership.DeleteUser("chb_chb");
            ////注意，如果requiresQuestionAndAnswer="true"，则必须提供密码问题及答案，下面的调用是requiresQuestionAndAnswer="false"的情况
            ////System.Web.Security.MembershipUser MUser = System.Web.Security.Membership.CreateUser("chb_chb", "HUbu88661126!@#");
            ////如果requiresQuestionAndAnswer="true",调用方法如下
            //System.Web.Security.MembershipUser MUser = System.Web.Security.Membership.CreateUser("chb_chb", "HUbu88661126!@#", "chb@qq.com", "aa", "bb", true, out staus);
            ////获取用户
            //MUser = System.Web.Security.Membership.GetUser("chb_chb");
            ////注意，如果requiresQuestionAndAnswer="fase"，调用方法如下
            ////string resetPassword = MUser.ResetPassword();
            ////注意，如果requiresQuestionAndAnswer="true"，则必须提供密码答案
            //string resetPassword = MUser.ResetPassword("bb");
            ////修改密码，需提供旧密码
            //bool ifSuccess = MUser.ChangePassword(resetPassword, "hubu88661126!@#");

            ////对用户profile进行操作
            //System.Web.Profile.ProfileBase profile = System.Web.Profile.ProfileBase.Create(MUser.UserName, true);
            ////获取用户属性
            //string firstName = profile.GetPropertyValue("FirstName").ToString();
            ////设置用户属性
            //profile.SetPropertyValue("FirstName", "cui");
            ////保存用户属性
            //profile.Save();

            ////获取系统角色
            //string[] roles = System.Web.Security.Roles.GetAllRoles();
            ////获取某个用户角色
            //string[] rolesOfUser = System.Web.Security.Roles.GetRolesForUser("chb_chb");
            ////将某个用户加入某个角色
            //Roles.AddUserToRole("chb_chb", "admin");
            ////判断当前用户是否属于某个角色
            //bool isInAdminRole = System.Web.Security.Roles.IsUserInRole("admin");
            ////判断某个用户是否属于某个角色
            //isInAdminRole = System.Web.Security.Roles.IsUserInRole("chb_chb", "admin");
            ////将用户从某个角色中移除
            //Roles.RemoveUserFromRole("chb_chb", "admin");

            Roles.AddUserToRole(user, role);
        }
    }
}